export const useResizeM = () => {
  /**
   * 监听窗口大小变化，同步调整字体大小
   * @param baseFontSize 字体大小
   * @param baseWidth 设计稿宽度
   * @param baseHeight 设计稿高度
   * @param callback 变化回调
   */
  const resizeFontSize = (
    baseFontSize: number,
    baseWidth = 960,
    baseHeight = 600,
    callback?: (ratio: number) => void
  ) => {
    const setBaseFont = () => {
      const doc = document.documentElement
      const ratioW = doc.clientWidth / baseWidth
      const ratioH = doc.clientHeight / baseHeight

      const ratio = ratioH > ratioW ? ratioW : ratioH

      doc.style.fontSize = baseFontSize * ratio + 'px'

      callback && callback(ratio)
    }

    setBaseFont()

    window.addEventListener('resize', () => {
      setBaseFont()
    })
  }

  return {
    resizeFontSize
  }
}
